<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/8/13/013
 * Time: 9:39
 */

namespace App\Http\Controllers\Agent;

use App\Http\Service\Agent\AgentService;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Session;
use Config;

class AgentController extends Controller
{

    public function disman()
    {
        return view("Index.disman");
    }

    /**
     * @param Request $request
     * @return bool|mixed|string
     * 获取一级代理列表
     */
    public function getFirstAgentList(Request $request)
    {
        $where = $request->except('_token');
        $where['token'] = Session::get(config::get('custom.setting.MEMBER_TOKEN'));
        $agent = new AgentService();
        $data = $agent->getAgentList($where);

        return $data;
    }

    /**
     * @param Request $request
     * @return bool|mixed|string
     * 获取二级代理列表
     */
    public function getSecAgentList(Request $request)
    {
        $where = $request->except('_token');
        $where['token'] = Session::get(config::get('custom.setting.MEMBER_TOKEN'));
        $agent = new AgentService();
        $data = $agent->getSecAgentList($where);
        return $data;
    }


    /**
     * @param Request $request
     * @return array
     * 添加代理接口
     */
    public function addAgentAccount(Request $request)
    {
        if(empty($request->all()))
        {
            return ['error_code'=>10201,'error_message'=>'参数为空'];
        }

        $where = $request->except('_token');
        $where['token'] = Session::get(config::get('custom.setting.MEMBER_TOKEN'));

        $agent = new AgentService();
        $data = $agent->doAgentAdd($where);
        return $data;
    }

    /**
     * @param Request $request
     * @return array|bool|mixed|string
     * 删除代理信息
     */
    public function deleteAgentAccount(Request $request)
    {
        if(empty($request->input('agent_id')))
        {
            return ['error_code'=>10201,'error_message'=>'参数为空'];
        }

        $where = $request->except('_token');
        $where['token'] = Session::get(config::get('custom.setting.MEMBER_TOKEN'));

        $agent = new AgentService();
        $data = $agent->doAgentDelete($where);
        return $data;

    }


    /**
     * @param Request $request
     * @return array|bool|mixed|string
     * 编辑代理用户信息
     */
    public function updateAgentAccount(Request $request)
    {
        if(empty($request->all()))
        {
            return ['error_code'=>10201,'error_message'=>'参数为空'];
        }

        $where = $request->except('_token');
        $where['token'] = Session::get(config::get('custom.setting.MEMBER_TOKEN'));

        $agent = new AgentService();
        $data = $agent->doAgentUpdate($where);
        return $data;
    }


    /**
     * @param Request $request
     * @return array|bool|mixed|string
     *  充值
     */
    public function rechargeAgentAccount(Request $request)
    {
        if(empty($request->all()))
        {
            return ['error_code'=>10201,'error_message'=>'参数为空'];
        }

        $where = $request->except('_token');
        $where['token'] = Session::get(config::get('custom.setting.MEMBER_TOKEN'));

        $agent = new AgentService();
        $data = $agent->doAgentRecharge($where);
        return $data;
    }

    /**
     * @param Request $request
     * @return bool|mixed|string
     * 获取唯一邀请码
     */
    public  function getFcode(Request $request)
    {

        $where = $request->except('_token');
        $where['token'] = Session::get(config::get('custom.setting.MEMBER_TOKEN'));

        $agent = new AgentService();
        $data = $agent->getFcode($where);
        return $data;
    }
}